$("header ul li").click(function(){	
	if($(this).hasClass("checked")){	
		
	}else{
		$('.clear').html('');
		$(".file").toggle();
		$(".PNR").toggle();
	}	
	$(this).addClass("checked").siblings().removeClass("checked");
})


/*——————————————————————————————上传————————————————————————————————*/
var sureTicketData = "";
$(".submit").click(function() {
	sureTicketData = "";
	$('.clear').html('')
	var fileName = $('.postFileName').val()
	if (fileName == '') {
		layer.msg('请选择文件',{icon:2});
		return false;
	}
	if (!(fileName.match(/.xls/i) || fileName.match(/.txt/i))) {
		layer.msg("文件格式不对,请选择.xls或者txt格式的文件",{icon:2});
		return false;
	} else {
		$('.submit').prop("type", "submit");
		layer.load();
		var ajaxFormOption = {
			type : "post", // 提交方式
			dataType : "json", // 数据类型
			url : "../ticket/importExcel?temp="+Math.random(), // 请求url
			success : function(data) {
				layer.closeAll('loading');
				$('.clear').html('');
				if (data.status==1002) {
					layer.alert('上传失败'+data.message);
					return false;
				}else{
					dataDraw(data)
					sureTicketData = data.data.orderList;
				}				
			}
		}
		$(".formData").ajaxSubmit(ajaxFormOption);
	}
	return false;
});
//pnr查询
$(".pnrSubmit").click(function(){
	sureTicketData = "";
	$('.clear').html('');
	var ICSPNR = $(".PNRNo").val();
	if(ICSPNR==""){
		layer.msg("ICSPNR不能为空")
		return false;
	}else{
		layer.load();
		$.ajax({
			type:"get",
			url:"../ticket/parsePNR?ICSPNR="+ICSPNR+"&temp="+Math.random(),
			dataType:"json",
			async:true,
			success:function(data){
				layer.closeAll('loading');
				$('.clear').html('');
				if(data.status==1002){
					layer.alert(data.message)
				}else{
					dataDraw(data);
					sureTicketData = data.data.orderList;
				}
			}
		})
	}
	
})
/* ——————————————————————————————确认票号———————————————————————————————— */
	
	$('.sureTicket').click(function(){
		if(sureTicketData!=""){
			 layer.load();
			 var postData = sureTicketData;
			 $.ajax({
				 type:"post",
				 url:"../ticket/insertTicket?temp="+Math.random(),
				 contentType:'application/json;charset=utf-8',
				 data:JSON.stringify(postData),
				 dataType:"json",
				 async:true,
				 success:function(data){	
					 layer.closeAll('loading');
					 if(data.status.toString()=="1001"){
						 layer.alert(data.message,{icon: 1,title:['提示','background-color:#00aa98;color:#fff']});		
						}else{
							layer.alert('更新票号失败'+data.message,{icon: 2,title:['提示','background-color:#00aa98;color:#fff']});
						}
				 }
			 })
		}else{
			layer.alert("无法确认票号");
		}	
		
	});



/*——————————————————————————————点击订单号进入订单详情————————————————————————————————*/
$('.tableData').delegate(".orderId","click",function(){	
	var id=$(this).text();//获取当前订单状态的id值	
	layer.open({
		type: 2,
		title: false,
		shadeClose: true,
		closeBtn: 0,
		shade: [0.9,'#cfcfcf'],
		area: ['98%', '98%'],  
		content: ['../ak/embedDiv.html?id='+id],// iframe的url，no代表不显示滚动条
		end:function(){
			
		}
			
	});
 })

 
 
function dataDraw(data){	
	var str = "";
	var length=data.data.orderList.length;
	$(".clickMes7").text(length);
	$(".clickMes5").text(data.data.matchCount+"/"+data.data.importCount)
	for(var i=0;i<length;i++){
		var data_ = data.data.orderList[i];		
		var passengersLength = data_.passengers.length;//获取旅客信息的数组长度  合并单元格
		var itinerariesLength = data_.itineraries.length;
		for(var m=0;m<passengersLength;m++){
			var connectImg = "";
			if(m==0){
				if(data.connect==1) connectImg = "connectImg";
				str += "<tr class='orderMainTr'>"+
						"<td colspan='11'>" +
							"<span class="+connectImg+">" +
								"订单号 : <span class='orderId fontf9a000'>"+ data_.id+"</span>"+
							"</span>" +
							"<span>" +
								"客户 : <b class='font00aa98'>"+ data_.customer+"</b>" +
							"</span>" +
							"<span class='font00aa98'><b>" 
				for(var j=0;j<itinerariesLength;j++){
					if(j==itinerariesLength-1){
						str += data_.itineraries[j].flightNumber +"&nbsp;&nbsp;"+ data_.itineraries[j].departureAirportCode+"-"+data_.itineraries[j].arriveAirportCode+"&nbsp;&nbsp;"+data_.itineraries[j].departureDate
					}else{
						str += data_.itineraries[j].flightNumber +"&nbsp;&nbsp;"+ data_.itineraries[j].departureAirportCode+"-"+data_.itineraries[j].arriveAirportCode+"&nbsp;&nbsp;"+data_.itineraries[j].departureDate+"/"
					}
				}
					str += 	"</b></span>" +
						"</td>"
				
			}
			/*if(m==0){
				//此处为判断为联程的加上图标begin
				if(data.connect==1){
					str+='<tr>'+
						'<td colspan="2" class="order_link connectImg">订单号 : <span class="orderId">'+ data_.id+'</span><span class="fontaaaaaa"> 客户 : <b class="font00aa98">'+ data_.customer+'<b></span></td>'
				}else{
					str+='<tr>'+
					'<td colspan="2" class="order_link">订单号 : <span class="orderId">'+ data_.id+'</span><span>客户 : <b class="font00aa98">'+ data_.customer+'<b></span></td>'
				}
				
			str+='<td class="font00aa98" colspan="8">'
				for(var j=0;j<itinerariesLength;j++){
					str+=data_.itineraries[j].flightNumber +"&nbsp;&nbsp;"+ data_.itineraries[j].departureAirportCode+"-"+data_.itineraries[j].arriveAirportCode+"&nbsp;&nbsp;"+data_.itineraries[j].departureDate+"/"
				}
				str += '</td></tr>';				
			}				*/
        	var email = data_.passengers[m].email?data_.passengers[m].email:"";
        	var name = "";
			if(commomFun.toEmptyString(data_.passengers[m].chineseSurname)==""&&commomFun.toEmptyString(data_.passengers[m].chineseName)!=""){				
				name = data_.passengers[m].chineseName;
			}else if(commomFun.toEmptyString(data_.passengers[m].chineseSurname)!=""){
				name = data_.passengers[m].chineseSurname+commomFun.toEmptyString(data_.passengers[m].chineseName);
			}else{
				name = commomFun.toEmptyString(data_.passengers[m].englishSurname)+commomFun.toEmptyString(data_.passengers[m].englishName);
			}       	
			str+='<tr>'+
					  '<td>'+name+'</td>'+
		    	 	  '<td>'+commomFun.typeNumStr(data_.passengers[m].type)+'</td>'+
		    	 	  '<td>'+commomFun.certificateTypeStr(data_.passengers[m].certificateType)+'</td>'+
		    	 	  '<td>'+commomFun.toEmptyString(data_.passengers[m].certificateNumber)+'</td>'+
		    	 	  '<td>'+email+'</td>'+
		    	 	  '<td>'+commomFun.toEmptyString(data_.passengers[m].birthDate)+'</td>'+
		    	 	  '<td>'+commomFun.genderStr(data_.passengers[m].gender)+'</td>'+
		    	 	  '<td>'+commomFun.toEmptyString(data_.passengers[m].issuingCountry)+'</td>'+
		    	 	  '<td>'+commomFun.toEmptyString(data_.passengers[m].country)+'</td>'+
		    	 	  '<td>'+commomFun.toEmptyString(data_.passengers[m].certificateExpireDate)+'</td>'+
		    	 	  '<td>'+commomFun.toEmptyString(data_.passengers[m].ticketNumber)+'</td>'+
    	         '</tr>'
    	 	  
		}
	}
	$(".clear").append(str)
}